package br.ucb.sigplan.util;

import java.net.MalformedURLException;
import java.text.MessageFormat;
import java.util.Calendar;

import javax.servlet.http.HttpServletRequest;


public class RecuperaSenhaUtil {
	
//	private final static String SENHA_DEFAULT="12345"; 	
	private static final String CONFIRM_URL_PATTERN = "{0}/confirmarResetarSenha.do?id={1}&email={2}";
	
//	public static int geraSenha (){
//	    int sec = Calendar.getInstance().get(Calendar.SECOND);
//	    int senhaint = new Integer(SENHA_DEFAULT.hashCode() * sec ).intValue();
//	    
//	    if (senhaint < 0){	    
//	    	senhaint = senhaint * -1;
//	    }
//	    
//	    return senhaint;
//	    
//	}
	
	public static void enviaEmailRedefinirSenha (String destino, String subject, HttpServletRequest req, String matricula) throws MalformedURLException{
		EmailUtil.sendMail( BodyEmail.getBodyRedefinirSenha(geraUrlConfirmacao(req, matricula.substring(0, 3), destino))
				, subject, destino);	
		
	}
	
	public static String geraUrlConfirmacao(HttpServletRequest req, String matricula, String email) throws MalformedURLException {
		return MessageFormat.format(CONFIRM_URL_PATTERN, new java.net.URL(req.getScheme(), req.getServerName(), req.getServerPort(), req.getContextPath()).toString(),
				matricula, email);
	}

}
